<template>
  <el-container class="home-container">
    <el-header>
      <div class="span-container" style="padding: 5px" @click="toWelcome">
        <img src="../assets/logo.png" alt="" height="40px" width="40px">
        <span>狼眼电影后台管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapsed ? '64px' : '250px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <!--侧边栏菜单-->
        <el-menu
            background-color="#333744"
            text-color="#fff"
            active-text-color="#409EFF"
            unique-opened
            :collapse="isCollapsed"
            :collapse-transition="false"
            :router="true"
            :default-active="$route.path">
          <!--一级菜单-->
          <el-submenu :index="String(item.id)" v-for="item in menulist" :key="item.id">
            <!--一级菜单的模板区域-->
            <template slot="title">
              <!--图标-->
              <i :class="iconlist[item.id]"></i>
              <!--文本-->
              <span>{{item.name}}</span>
            </template>
            <!--二级菜单-->
            <el-menu-item :index="'/' + subItem.path" v-for="subItem in item.children" :key="subItem.id">
              <template slot="title">
                <!--图标-->
                <i class="el-icon-menu"></i>
                <!--文本-->
                <span>{{ subItem.name }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
        <div class="particle-rotation" v-show="showParticleRotation" v-cloak></div>
      </el-main>
    </el-container>
  </el-container>
</template>



<script>


export default {
  name: "Home",
  components: {
    
  },
  data(){
    return {
      //左侧菜单数据
      menulist:[],
      iconlist: {
        '1': 'el-icon-s-home',
        '2': 'el-icon-video-camera-solid',
        '3': 'el-icon-s-help',
        '4': 'el-icon-message-solid',
        '5': 'el-icon-s-custom',
        '6': 'el-icon-user-solid',
        '7': 'el-icon-warning'
      },
      isCollapsed: false,
      showParticleRotation : true
    }
  },
  name: "Home",
  created(){
    this.getMenuList()
    // 隐藏粒子旋转效果
    this.hideParticleRotation()
  },
  watch:{
    //只要地址栏中的url 发生了改变，就会被监听到
    "$route.path": function (newVal, oldVal) {
      //console.log(newVal + ' --- ' + oldVal)
      if (newVal!='/welcome'){
        // 方法内 `this` 指向 vm 实例
        this.showParticleRotation = false
      } else {
        this.showParticleRotation = true
      }
    }
  },
  // 在 `methods` 对象中定义方法
  methods:{
    logout(){
      //清空sessionStorage
      window.sessionStorage.clear();
      this.$router.push('/login')
    },
    async getMenuList(){
      const loginUser = JSON.parse(window.sessionStorage.getItem("loginUser"))
      console.log(loginUser)
      this.menulist = loginUser.sysUser.sysRole.children
    },
    // 菜单展开与闭合：点击事件
    toggleCollapse(){
      this.isCollapsed = !this.isCollapsed
    },
    toWelcome(){
      this.$router.push('/welcome')
    },
    hideParticleRotation(){
      if (this.$route.path!='/welcome'){
        this.showParticleRotation = false
      }
    }
  }
}
</script>

<style scoped>

[v-cloak] {
  display: none;
}

.home-container{
  height: 100%;
}

.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: whitesmoke;
  font-size: 20px;
}

.el-header > div{
  display: flex;
  align-items: center;
}

div > span{
  margin-left: 15px;
}

.el-aside {
  background-color: #333744;
}


.toggle-button{
  background-color: #4A5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.1em;
  cursor: pointer;
}

.span-container{
  cursor: pointer;
}

.el-main{
  background: url("../assets/welcome.jpg");
  background-size: cover;
  position: relative;
}

.particle-rotation{
  position:absolute;
  top: 24%;
  left: 47.7%;
  width: 125px;
  height: 125px;
  border-radius: 50%;
  background: url("../assets/bg.gif") repeat #0a0a0a !important;
  z-index: 0;
  mask: linear-gradient(-90deg, black, transparent);
}

.el-menu{
  border: solid 0 grey;
}

</style>
